<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const obj = {
      a: 10,
      b: 20
    }
    var a = 100;
    // Object.defineProperty 拦截对象
    Object.defineProperty(obj, 'a', {
      /* 
        可以拦截 对象的这个属性
          取值拦截
          赋值拦截
      */
      // getter拦截器 拦截该属性的取值
      get(){
        console.log('a属性getter触发');
        return a;
      },
      // setter 拦截 该属性的赋值
      set(val){
        console.log('a属性setter触发',val);
        a = val;
      }
    })

    console.log(obj.a);

    obj.a = 1000;
    console.log(obj.a);
  </script>
</body>
</html>